package com.sumainfor.pc.epc.controller.engineering;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.epc.service.DecorateComboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 */
@RestController
@RequestMapping("/engineering/decoratecombo")
public class DecorateComboController implements Serializable{

    @Autowired
    private DecorateComboService decorateComboService;
    /*
     *分页查询装修套餐
     */
    @RequestMapping(value = "/getDecorateComboList",method = RequestMethod.GET)
    public JsonResult getDecorateComboList(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=decorateComboService.getDecorateComboListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> list=decorateComboService.getDecorateComboList(params);
        result=pageUtils.getJsonResult(list, params, cout);
        return result;
    }
    /**
     * 新增装修套餐 主表
     * @param params
     * @return
     */
    @RequestMapping(value = "/addDecorateCombo",method = RequestMethod.POST)
    public JsonResult addDecorateCombo(@RequestBody Map<String,Object> params){
        JsonResult result=new JsonResult();
        if(decorateComboService.addDecorateCombo(params)>0){
            result.putSuccess("创建装修套餐成功！");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }
    /**
     * 修改装修套餐停用启用状态
     */
    @RequestMapping(value = "/updateDecorateCombo",method = RequestMethod.POST)
    public JsonResult updateDecorateCombo(@RequestBody Map<String,Object> params){
        JsonResult result=new JsonResult();
        if(decorateComboService.updateDecorateCombo(params)>0){
            result.putSuccess("修改成功");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }
    /**
     * 编辑装修套餐的时候回显数据
     */
    @RequestMapping(value = "/getDecorateComboByCombId",method = RequestMethod.GET)
    public JsonResult getDecorateComboByCombId(@RequestParam Map<String,Object> params){
        JsonResult result=new JsonResult();
        Map<String,Object> map=decorateComboService.getDecorateComboByCombId(params);
        if(map!=null){
            result.put(map);
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }
    /**
     * 修改装修套餐停用启用状态
     */
    @RequestMapping(value = "/updateDecorateComboAndInfo",method = RequestMethod.POST)
    public JsonResult updateDecorateComboAndInfo(@RequestBody Map<String,Object> params){
        JsonResult result=new JsonResult();
        if(decorateComboService.updateAndInfo(params)>0){
            result.putSuccess("修改成功");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

}
